package org.zhadoop.stream.cql.exception;

import org.zhadoop.streaming.exception.ErrorCode;
import org.zhadoop.streaming.exception.StreamingException;
import org.zhadoop.streaming.exception.StreamingRuntimeException;

/**
 * 执行期间异常
 * @author zwd
 *
 */
public class ExecutorException extends CQLException{

	private static final long serialVersionUID = -3381386285286161756L;

	/**
     * <默认构造函数>
     *
     */
    public ExecutorException(ErrorCode errorCode, String... errorArgs){
        super(errorCode, errorArgs);
    }
    
    /**
     * <默认构造函数>
     *
     */
    public ExecutorException(Throwable cause, ErrorCode errorCode, String... errorArgs){
        super(cause, errorCode, errorArgs);
    }
    
    /**
     * <默认构造函数>
     * 仅供内部warp函数使用
     *
     */
    protected ExecutorException(Throwable cause, String fullMessage, ErrorCode errorCode){
        super(cause, fullMessage, errorCode);
    }
    
    /**
     * 包装系统异常到ExecutorException
     *
     */
    public static ExecutorException wrapException(Exception exception){
        return new ExecutorException(exception.getCause(), exception.getMessage(),ErrorCode.UNKNOWN_ERROR);
    }
    
    /**
     * 包装StreamingException
     *
     */
    public static ExecutorException wrapStreamingException(StreamingException exception){
        return new ExecutorException(exception.getCause(), exception.getMessage(), exception.getErrorCode());
    }

    /**
     * 包装StreamingException
     *
     */
    public static ExecutorException wrapStreamingRunTimeException(StreamingRuntimeException exception){
        if(exception.getErrorCode() != null){
            return new ExecutorException(exception.getCause(), exception.getMessage(), exception.getErrorCode());
        }

        return new ExecutorException(exception.getCause(), exception.getMessage(), ErrorCode.UNKNOWN_ERROR);
    }
}
